// 这里的目的是为了让 firstPage 以最快的速度加载，并将图片渲染出来，避免长时间的屏幕空白
class FirstPageAddon{
    static apply(fp) {
        let fpa = new FirstPageAddon(fp);
        fp.show();
        return fpa;
    }
    constructor(fp) {
        this.fp = fp;
        this.loading = {
            divs: [],
            arr: [],
            ok: '',
            id: null,
            div: null,
            time: 6,
            cur: 0
        };
        this._init()
    }
    _init() {
        this.infoDiv = this.fp._createDom('div',{ position: 'absolute',bottom: '5px', left: '5px', width: '500px',
            height: '100px',lineHeight: '25px',zIndex: 15,whiteSpace: "nowrap", overflow: 'hidden', textOverflow: "ellipsis", background: 'white',
            borderRadius: '5px', padding: '3px', opacity: 0.5},);
        this.fp.topDiv.append(this.infoDiv);
    }
    // 结束加载动画
    over() {
        setTimeout(() => {
            clearInterval(this.loading.id);
            this.loading.id = null;
            this.loading.div.innerHTML = this.loading.ok;
            setTimeout(() => {
                this.infoDiv.style.display = 'none';
            },200);
        },100)
    }
    // 显示加载文件的动画
    addText(text,ok) {
        if (this.loading.id) {
            clearInterval(this.loading.id);
            this.loading.div.innerHTML = this.loading.ok;
        }
        this.loading.div = this.fp._createDom('div',{lineHeight: '25px',height: '25px',fontsize:'18px'});
        this.loading.div.innerHTML = text;
        this.loading.cur = 0;
        let dots = '';
        this.loading.ok = ok || (text + '&nbsp;&nbsp;√');
        this.loading.arr = [];
        for (let i = 0;i < this.loading.time;i++) {
            this.loading.arr.push(`${text}&nbsp;&nbsp;${dots}`)
            dots += '.';
        }
        this.loading.id = setInterval(() => {
            this.loading.div.innerHTML = this.loading.arr[this.loading.cur];
            this.loading.cur++;
            this.loading.cur %= this.loading.time;
        },500);
        this.loading.divs.push(this.loading.div);
        if (this.loading.divs.length > 4) {
            this.loading.divs.shift().remove();
        }
        this.infoDiv.appendChild(this.loading.div);
    }
}
